<!DOCTYPE html>
<!--suppress ThymeleafVariablesResolveInspection-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="Responsive Admin Dashboard Template">
        <meta name="keywords" content="admin,dashboard">
        <meta name="author" content="skcats">
		<title></title>
		<link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all" />
        <link th:href="@{/assets/plugins/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
        <link th:href="@{/assets/plugins/font-awesome/css/font-awesome.min.css}" rel="stylesheet">
        <link th:href="@{/assets/css/custom.css}" rel="stylesheet">
	</head>
    <style>
        .utable .layui-laypage .layui-laypage-curr .layui-laypage-em {
            background-color: #1E9FFF;
        }
        .layui-table-page {
            text-align: center;
        }
        .layui-table {
            text-align: center;
            margin-top: -10px;
        }
        .layui-table-view thead th {
            text-align: center;
            font-weight: bold;
        }
        .layui-table-view tbody td {
            text-align: center;
        }
    </style>
<body>
<!--数据表格样式及附件-->
<script type="text/html" id="bar">
    <a id="upd" class="layui-btn layui-btn-xs" lay-event="upd">
        <i class="layui-icon">&#xe60a;</i>回复
    </a>
    {{#  if(d.status == 1){ }}
    <a id="ann" class="layui-btn layui-btn-warm layui-btn-xs" lay-event="no">
        <i class="layui-icon">&#x1006;</i>未修
    </a>
    {{# }if(d.status == 2) { }}
    <a class="layui-btn layui-btn-xs" lay-event="yes">
        <i class="layui-icon">&#xe605;</i>已修
    </a>
    {{#  } }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
        <i class="layui-icon">&#xe640;</i>丢弃
    </a>
</script>


<!--搜索狂-->
<form class="layui-form">
    <div class="layui-inline">
        <label class="layui-form-label" style="width: 100px">维修名称</label>
        <div class="layui-input-inline">
            <input id="mh" style="width: 150px" name="equipmenttype" placeholder="维修名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label" style="width: 100px">维修类型</label>
        <div class="layui-input-block">
            <select id="wxzt" name="status" style="height: 35px;width: 120px;" lay-filter="mySelect">
                <option value="">选择类型</option>
                <option value="1">未修好</option>
                <option value="2">已修好</option>
            </select>
        </div>
    </div>

    <div class="layui-inline">
        <label class="layui-form-label">部门</label>
        <div class="layui-input-block">
            <select id="depid" name="depid" style="height: 35px;width: 120px;" lay-filter="mySelect">
                <option value="">请选择部门</option>
                <option th:each="d:${dlist}" th:value="${d.depid}" th:text="${d.depname}">张先生</option>
            </select>
        </div>
    </div>

    <div class="layui-inline">
        <div class="layui-input-block" style="margin-left: 30px">
            <button id="ck" type="button" class="layui-btn layui-btn-sm layui-btn-normal"><i class="fa fa-spin fa-refresh"></i> 查找</button>
        </div>
    </div>
</form>


<!--数据表格  数据表格使用的是方法渲染-->
<div class="utable">
<table class="layui-table"
       lay-data="{width:1270,height:500, url:'/main/data', page:true, id:'tab'}"
       lay-filter="tab">
    <thead>
    <tr>
        <!--<th lay-data="{type: 'checkbox', fixed: 'left'}"></th>-->
        <th lay-data="{field:'wxid', width:80, sort: true}">编号</th>
        <th lay-data="{field:'emp_Name',width:100}">报修姓名</th>
        <th lay-data="{field:'equipmenttype',width:140}">维修设备名称</th>
        <th lay-data="{field:'className'}">学生所在班级</th>  <!--classno depid className depName-->
        <th lay-data="{field:'depName',width:140}">老师所在部门</th>
        <th lay-data="{field:'starttime',width:120}">开始时间</th>
        <th lay-data="{field:'endtime',width:120}">结束时间</th>
        <th lay-data="{field:'status', templet: '#zt',width:100}">维修状态</th>
        <th lay-data="{fixed: 'right', title:'操作', toolbar: '#bar', width:252}"></th>
    </tr>
    </thead>
</table>
</div>
</body>
<script th:src="@{/js/register/jquery-3.1.0.min.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script type="text/html" id="zt">
    {{#  if(d.status ==1 ){ }}
    <span style="color:red">未修好</span>
    {{#  } else { }}
    <span style="color:green">已修好</span>
    {{#  } }}
</script>
<script type="text/javascript" th:inline="none">

    layui.use('table', function () {
        var table = layui.table;

        //模糊
        $("#ck").on('click',function(){
            var equipmenttype=$("#mh").val();
            var status=$("#wxzt").val();
            var depid=$("#depid").val();
            table.reload('tab', {
                where: { //设定异步数据接口的额外参数，任意设
                    equipmenttype: equipmenttype,
                    status:status,
                    depid:depid,
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        });

        //去到修改界面
        function upd(wxid){
            //iframe窗
            layer.open({
                type: 2,
                title: '回复',
                maxmin: true, //开启最大化最小化a按钮
                area: ['400px', '300px'],
                content: ['/main/maintoupd?wxid='+wxid]//这是链接你的页面地址 url
            });
        }

        //监听行工具事件
        table.on('tool(tab)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'de' +
                '' +
                '' +
                'l') {
                layer.confirm('真的删除么?', function (index) {
                    obj.del();
                    layer.close(index);
                    $.ajax({
                        url: '/main/del',
                        type: 'post',
                        data: {
                            wxid:data.wxid
                        },
                        dataType: 'text'
                    })
                });
            }else if(obj.event == 'upd'){//修改
                upd(data.wxid)
            }

            else if (obj.event == "yes") {//禁用
                $.ajax({
                    url: '/main/set',
                    type: 'post',
                    data: {
                        wxid:data.wxid,
                        status:data.status,
                    },
                    dataType: 'json',
                    success : function(data) {
                        if (data){
                            //执行重载
                            $('.layui-laypage-btn').click();
                        }
                    }
                })
            } else if(obj.event === 'no'){//启用
                $.ajax({
                    url: '/main/set',
                    type: 'post',
                    data: {
                        wxid:data.wxid,
                        status:data.status,
                    },
                    dataType: 'json',
                    success : function(data) {
                        if (data){
                            //执行重载
                            $('.layui-laypage-btn').click();
                        }
                    }
                })
            }
        })
    });
</script>
</html>